/*
  function: phy_move_towards_point();
  param: argument0, integer, index of instance to move
  param: argument1, integer, horizontal destination point
  param: argument2, integer, vertical destination point
  param: argument3, integer, the maximum magnitude of the force vector
  return: nothing
*/

var instance_to_move, x_destination, y_destination, magnitude;

instance_to_move = argument0;
x_destination = argument1;
y_destination = argument2;
magnitude = argument3;

//Apply a force to this instance in the determined direction with a certain magnitude.
with (instance_to_move) {
  the_distance = point_distance(phy_position_x, phy_position_y, x_destination, y_destination);
  the_direction = point_direction(phy_position_x, phy_position_y, x_destination, y_destination);
  /* Finds a magnitude of sorts by measuring the vector from this entity
   * to the other one, capping the length at magnitude. */
  var ldir_x = lengthdir_x(the_distance, the_direction)
  /* Make the AI move, with the X force being a product of their length
   * dir (X) times a constant. */
  //show_debug_message("(" + string(current_second) + ") Direction: " + string(the_direction) + ", Length: " + string(ldir_x))
  physics_apply_force(x, y, ldir_x * magnitude, 0)
}
